package com.riteny.token.helper.parse;

import com.riteny.token.helper.exception.TokenVaildException;
import org.apache.commons.lang.StringUtils;

/**
 * @author Riteny
 * 2020/9/16  15:05
 */
public class HeaderTokenParserImpl implements HeaderTokenParser {

    @Override
    public String parese(String headerStr) throws TokenVaildException {

        if (StringUtils.isEmpty(headerStr)) {
            throw new TokenVaildException("invalid_token", "Token not found .");
        }

        String[] tokenFormat = headerStr.split(" ");

        if (tokenFormat.length < 2) {
            throw new TokenVaildException("invalid_token", "Token format error . ");
        }

        String tokenType = tokenFormat[0];

        String token = tokenFormat[1];

        return token;
    }
}
